/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.faytechcc.csc251.gui;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author User
 */
class PreviewPanel
        extends JPanel
{

    private ImageIcon cardImage;
    private JLabel imageLabel;

    public PreviewPanel()
    {
        this.setBorder(BorderFactory.createTitledBorder("Preview"));
        cardImage = new ImageIcon("cardBack.jpg");
        imageLabel = new JLabel();
        imageLabel.setIcon(cardImage);
        this.add(imageLabel);
    }
    
    public void setImage(String cardName, String setName)
    {
        String path = "MTGDatabase Card Images\\Originals\\"
                + setName + "\\" + cardName + ".jpg";
        ImageIcon newImage = new ImageIcon(path);
        this.imageLabel.setIcon(newImage);
    }
    
     public class ImageListener
            implements ListSelectionListener
    {

        private PreviewPanel pPanel;
        private ResultsPanel rPanel;

        public ImageListener(PreviewPanel pPanel, ResultsPanel rPanel)
        {
            this.pPanel = pPanel;
            this.rPanel = rPanel;
        }

        @Override
        public void valueChanged(ListSelectionEvent lse) {
            String cardName = rPanel.getSelectedCardName().trim();
            String setName = rPanel.getSelectedCardSet().trim();
            pPanel.setImage(cardName, setName);
        }
     }
}
